#include "Common.fxh"

Texture2D gLightingBuffer;
Texture2D gSSAOMap;

float gSSAO;

struct VS_IN
{
	float3 posL     : POSITION;
};

struct VS_OUT
{
	float4 posD         : SV_POSITION;
	float2 texCoord     : TEXCOORD0;
};

VS_OUT VS(VS_IN vIn)
{
	VS_OUT vOut;

	float4 posH = float4(vIn.posL, 1.f);
	vOut.posD = posH;
	vOut.texCoord = posH.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
	
	return vOut;
}

float4 PS(VS_OUT pIn) : SV_Target
{
	float ssao = gSSAOMap.Sample(gPointSam, pIn.texCoord).r;
	ssao = gSSAO == 1.0f ? ssao : 1.0f;

	float3 lightAccumValue = gLightingBuffer.Sample(gPointSam, pIn.texCoord).rgb;
	return float4(ssao * lightAccumValue, 1.0f);
}

technique11 tech
{
	pass P0
	{
		SetVertexShader( CompileShader( vs_5_0, VS() ) );
		SetGeometryShader( NULL );
		SetPixelShader( CompileShader( ps_5_0, PS() ) );
		
		SetDepthStencilState(DepthOff, 0);
		SetRasterizerState(CullBack);
	}
}
